home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 102_01.zip / RALLY.C < prev    next >
C/C++ Source or Header  |  1993-06-03  |  4KB  |  181 lines

  1. /*
  2.     H19 RALLY Game,        5/80    Steve Ward
  3.  
  4.     Works ONLY on Heathkit/Zenith H19/Z19 terminal
  5.                  (or H89 computer)
  6.  
  7.     Command format:
  8.  
  9.     A>rally [-rn] [-b] [mapname] [-dx] <cr>
  10.  
  11.     where:    "n"  is an optional seed for the random number generator
  12.              (results in exactly the same minor track deviations each
  13.              time it is given with a particular track);
  14.              If "n" is omitted, then track deviations are totally
  15.              random for each session (but same for each run in any
  16.              single session.)
  17.  
  18.         "-b" is a debugging option doing Steve-knows-what.
  19.  
  20.         "mapname" specifies the map file to use for the track
  21.             (defaults to "rally.map").
  22.  
  23.         "x"  is a delay count for use in putting in a delay after
  24.              every "insert line" sequence is sent to the H19. This
  25.              should only be used if your H19 hangs in the middle of
  26.              a game--which only happens if you're running the H19 at
  27.              19,200 baud (like I am.) (The delay defaults to DELAYV.)
  28. */
  29.  
  30.  
  31. #include "bdscio.h"        /* Get std console parameters    */
  32.  
  33. #define DELAYV  25        /* Should be 0 if not running at 19,200 baud */
  34. #define    CARY    16        /* Y position of car.        */
  35. #define    IBAD    0
  36. #define    LSPEED    7        /* Line 25 label posns        */
  37. #define    LMILES    20
  38. #define    MAXSPD    9
  39. #define    SPDSCL    128
  40. #define    TENTHS    10        /* Number of lines per mile.    */
  41. #define    TICMIN    1920        /* Number of tics per minute.    */
  42.  
  43. char    Free[10000], *Freep;
  44.  
  45. char    CRTFrz, CRTChr;
  46. int    Miles;
  47. char    Pavement, Freeze, BFlag;
  48. char    CurX, CurY, SignY;
  49. int    CarX, CarDX;
  50. char    RevFlg, AltFlg;
  51. int    Speed, Tenths;
  52. char    Image[CARY*80+80];
  53. char    *ImPtr, *ImEnd;
  54. int    Seed;
  55. int    Ranno;
  56. char    InBuf[BUFSIZ], SavChr;
  57. int    SpTime[MAXSPD+1];
  58.  
  59. int    ddelay;
  60.  
  61. struct Road {
  62.     struct Node *Next;
  63.     char    active;
  64.     char    Token;
  65.     int    Windy;
  66.     int    Curvy;
  67.     int    Age;
  68.     int    ToGo;
  69.     char    Holes;
  70.     char    X;
  71.     char    dx;
  72.     char    width; } Road1, Road2;
  73.  
  74. struct Sign {
  75.     struct Node *Next;
  76.     char key;
  77.     char text[0]; };
  78.  
  79. struct Fork {
  80.     struct Node *Next;
  81.     char key;
  82.     char *Branch; };
  83.  
  84. struct Dist {
  85.     struct Node *Next;
  86.     char key;
  87.     char wid, curve, wind;
  88.     int miles; };
  89.  
  90. union Node {
  91.     struct Dist;
  92.     struct Fork;
  93.     struct Sign; } *Tag[128];
  94.  
  95.  
  96. /*
  97.     Write a character to the terminal, handling X-ON/X-OFF
  98.     protocol and not going into a busy loop if the terminal
  99.     isn't ready to send a character, but rather just returning
  100.     in that case to let the caller do more crunching and try
  101.     again later.
  102. */
  103.  
  104. putchar(c)
  105.  {    char stat, ch;
  106.     for(;;)
  107.      { if ((CIMASK & (stat = inp(CSTAT))) == (CAHI ? CIMASK : 0))
  108.         switch(ch = (0177 & inp(CDATA))) {
  109.         case 'S'-64:    CRTFrz=1; break;
  110.         case 'Q'-64:    CRTFrz=0; break;
  111.         case 'C'-64:    puts("\033z"); exit();
  112.         default:    CRTChr=ch; }
  113.        if (CRTFrz) continue;
  114.        if ((stat & COMASK) == (CAHI ? COMASK : 0))
  115.          { if (c) outp(CDATA,c); return; }
  116.      }
  117. }
  118.  
  119.  
  120. char *new(size)
  121.  {    char *rr;
  122.     rr = Freep; Freep += size; return rr; }
  123.  
  124. struct Dist *NRoad(widx, curv, windx, dist)
  125.  {    struct Dist *rr;
  126.     rr = new(sizeof *rr);
  127.     rr->key = 'D';        rr->Next = 0;
  128.     rr->miles = dist;    rr->wid = widx;
  129.     rr->curve = curv;    rr->wind = windx;
  130.     return rr; }
  131.  
  132. struct Sign *NSign(txt)
  133.  char *txt;
  134.  {    int leng; char *cc, *dd;
  135.     struct Sign *ss;
  136.     leng = sizeof *ss; leng++;
  137.     for (cc=txt; *cc++; leng++);
  138.     ss = new(leng);        ss->key = 'S';        ss->Next = 0;
  139.     dd = &(ss->text); for (cc=txt; *dd++ = *cc++;);
  140.     return ss; }
  141.  
  142. struct Fork *NFork(kk)
  143.  {    struct Fork *ff;
  144.     ff = new(sizeof *ff); ff->key = kk;
  145.     ff->Next = 0;    ff->Branch = 0;
  146.     return ff; }
  147.  
  148. PrNode(nn)
  149.  struct Node *nn;
  150.  {    printf("Node %x: %c -> %x \r\n", nn, nn->key, nn->Next); }
  151.  
  152. char rdc()
  153.  {    char ch;
  154.     if (ch = SavChr) { SavChr=0; return ch; };
  155.     return (getc(InBuf)); }
  156.  
  157. char pkc()
  158.  {    return (SavChr = rdc()); }
  159.  
  160. int rdn()
  161.  {    int ans, ch;
  162.     ans = 0;
  163.     while (isdigit(pkc()))    ans = ans*10 + (rdc() - '0');
  164.     return ans; }
  165.  
  166. struct Dist *LRoad()
  167.  {    int w, c, iwid, dd;
  168.     char ch;
  169.     dd = rdn();
  170.     w = -1; c = -1; iwid = 20;
  171.     while (pkc() != '\n') switch(rdc())
  172.      {    case '~':    c++; continue;
  173.         case 'W':    iwid = rdn(); continue;
  174.         case '!':    w++; continue;
  175.         default:    continue; }
  176.     return NRoad(iwid, c, w, dd);
  177.  }
  178.  
  179. struct Dist *Load(name)
  180.  char *name;
  181.  {    char c